package com.ericsson.common.util;

import org.slf4j.Logger;

import java.io.IOException;

/**
 * 常用的静态方法工具类
 * @author zhuguangrui
 */
public class CommonUtils {

    /**
     * 执行脚本，无需接入输入流的
     * @param scriptCmd
     */
    public static void execScriptCmd(String scriptCmd, Logger log) {

        Process proc;
        String[] cmd = new String[3];
        cmd[0] = "sh";
        cmd[1] = "-c";
        cmd[2] = scriptCmd;
        if(log != null) {
            log.info(cmd[2]);
        }
        try {
            proc = Runtime.getRuntime().exec(cmd);
            proc.waitFor();
        } catch (IOException|InterruptedException e) {
            e.printStackTrace();
            if(log != null) {
                log.error(e.getMessage(), e);
            }
        }
    }

    public static void fileMv(String srcFile, String dest) {
        execScriptCmd("mv " + srcFile + " " + dest,null);
    }


}
